<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
		<title>Instaright Bookmarklet Save Articles </title>
		<link rel="stylesheet" href="{{ env }}/css/nano.css" type="text/css"/>
		<link rel="stylesheet" href="{{ env }}/css/frame.css" type="text/css"/>
		<script type="text/javascript" src="{{ env }}/static/javascript/instaright.js"></script>
	</head>
	<body>
		<div id="bookmarklet">
			<div style="margin-bottom:8px">
				<table style="width:100%">
					<tr>
						<td><img src="/static/images/instaright_.png" alt="Send to Instaright" width="40" height="40"/></td>
						<td class="close"><a href="#" onclick="sendToParent('close'); return false"><img src="/static/images/close_white.png" alt="Close" title="Close" width="13" height="13"/></a></td>
					</tr>
				</table>
			</div>
			<div id="sharediv" class="sharebox expanded" style="border-width:0px">
				<form action="/a/bookmarklet" method="post" id="bookmarkletform">
					<div class="title field"><label for="title">Title:</label><input type="text" name="title" class="title" /></div>
					<div class="url field"><label for="url">Link:</label><input type="text" name="url" class="url" /></div>
					<div class="comment field"><textarea name="note" class="note" title="Add a note" rows="4" cols="40"></textarea></div>
					<div class="actions">
						<table style="width:100%">
							<tr>
								<td style="text-align:right; padding-left: 5px">
									<input type="submit" value="Post" style="font-weight:bold"/>
									<input type="hidden" name="parenturl"/>
									<input type="hidden" name="link_title"/>
									<input type="hidden" name="link" value=""/>
								</td>
							</tr>

							<tr>
								<td colspan="2" class="cc">
									<div class="ccbody">
										<table>
											<tr>
												<td class="ccbox"><input type="checkbox" name="share" value="1" checked="checked"/></td>
												<td class="cclabel"><span>Send Everywhere</span></td>
											</tr>
										</table>
									</div>
								</td>
							</tr>

						</table>
					</div>
				</form>
			</div>

			<div id="logindiv" style="display:none">
				<div id="errormessage" style="margin-bottom:1em; display:none"></div>
				<div class="sharebox expanded" style="border-width:0px ;padding:30px; margin-left: 50px;">
					<p class="howdy">Yee Haw! Claim your identity by logging at out website.</p>
					<p class="howdy"><a href="{{ env }}" target="_blank" >(login)</a></p>
					<p class="howdy">*try again after login</p>
				</div>

			</body>
		</div>
	</div>


	<script src="/static/javascript/jquery-1.3.js" type="text/javascript"></script>

	<script type="text/javascript">
		//<![CDATA[
	var gCurrentUserId = "8023d9c9d24f4ecb954dd401744f14d8";


	var gTwitLogin = 'bojanbabic';

	var gHttpsPrefix = 'https://friendfeed.com';
	var gRTL = false;
	//]]>
	</script>

	<script src="/static/javascript/nano.en.js" type="text/javascript">
	</script>
	<script type="text/javascript">
		//<![CDATA[
	var gLastHash = "";
	var gThumbnails = [];
	var kThumbHeight = 150;
	var kThumbWidth = 400;
	var kMaxThumbnails = 3;
	$(function() {

			var submit = function() { $("#bookmarkletform").submit() }
			$("textarea.note").hint().makeExpandable(20000, submit).focus(shareFocus);
			$("#bookmarkletform,#loginform").submit(bookmarkletSubmit); checkHash();
			setInterval(checkHash, 100);

			});
function checkHash() {
	var hash = location.href.split("#")[1]; // don't use location.hash
	if (!hash || !hash.length) return;
	var p = parseParams(hash);
	location.replace(location.href.split("#")[0] + "#");
	for (var i in p) {
		var v = p[i];
		switch (i) {
			case "parenturl":
				$("input[name=parenturl]").val(v);
			break;
			case "url":
				$("input[name=url]").val(v);
			$("input[name=link]").val(v);
			$("input[name=url]").attr('disabled',true);
			break;
			case "title":
				$("input[name=title]").val(v);
			$("input[name=link_title]").val(v);
			$("input[name=title]").attr('disabled',true);
			break;
			case "selection":
				v = $.trim(v);
			if (v) $("textarea[name=note]").val(('"' + v + '"').replace(/\n/g, " ")).removeClass("blur").keypress();
			break;
		}
	}
}
function updateFrameSize() {
	sendToParent('frameh-' + (document.body.offsetHeight + 40));
}
function sendToLoginPage(){
	var redirect_url = $('input[name=parenturl]').val().split('#')[0];
	var url="{{ env }}/user/dashboard?redirect="+redirect_url;
	try {
		top.location.replace(url);
	} catch (e) {
		if (window.console && window.console.log) {
			console.log(e);
		}
		top.location = url;
	}
}
function sendToParent(msg) {
	var url = $('input[name=parenturl]').val().split('#')[0] + "#FFSHARE-" + msg;
	try {
		top.location.replace(url);
	} catch (e) {
		top.location = url;
	}
}
function parseParams(s) {
	var r = {};
	var a = s.split("&");
	for (var i in a) {
		var kv = a[i].split("=");
		r[decodeURIComponent(kv[0])] = decodeURIComponent(kv[1]);
	}
	return r;
}
function bookmarkletSubmit() {
	var form = $("#bookmarkletform");
	var args = form.formToDict();
	if (!args.link) {
		return false;
	}
	var login = $("#loginform").formToDict();
	if (!getCookie("user_uuid")) {
		showLogin();
		return false;
	}
	if ($("textarea.note").hasClass("blur")) args.comment = "";
	var json_instaright = jsonifyInstarightObject(args);
	var submit = $("input[type=submit]");
	submit.disable();
	$.postJSON("/rpc", {'data':json_instaright}, function(r) {
			submit.enable();
			if (r.loginreq) {
			showLogin();
			} else if (r.message) {
			$("#errormessage").html(r.message).show();
			showLogin();
			} else {
			if (r.close_html) {
			sendToParent("close-" + encodeURIComponent(r.close_html).replace(/-/g, '%2d'));
			} else {
			sendToParent("close");
			}
			}
			}, submit, true);
	return false;
}
function showLogin() {
	$("#sharediv").css("display", "none");
	$("#logindiv").css("display", "block");
	$("#logindiv input[name=email]").focus();
	updateFrameSize();
}
function handleReshare() {
	return;
}
//]]>
</script>

</body>
</html>

